package com.sss.hloster02;

import java.util.Scanner;

public class TestDriver04 {

	public static void main(String[] args) {
		test01();
	}

	private static void test01() {
		int i = 0;
		int j = 0;
		int x = 0;
		int y = 0;
		Scanner input = new Scanner(System.in);
		System.out.print("请输入第一行列式的行数为：");
		i = input.nextInt();
		System.out.print("请输入第一行列式的列数为：");
		j = input.nextInt();
		System.out.print("请输入第二行列式的行数为：");
		x = input.nextInt();
		if (j != x) {
			System.out.print("不符合行列式运算法则，重新输入！");
			System.out.print("请输入第二行列式的行数为：");
			x = input.nextInt();
		}
		System.out.print("请输入第二行列式的行数为：");
		y = input.nextInt();

		int[][] arr01 = new int[i][j];
		int[][] arr02 = new int[x][y];
		int[][] arr03 = new int[i][y];
		System.out.println("请输入第一行列式：");
		Scanner sc = new Scanner(System.in);
		for (int m = 0; m <= i - 1; m++) {
			for (int n = 0; n <= j - 1; n++) {

				System.out.print("第一行列式的" + (m + 1) + "行，第" + (n + 1) + "列为：");
				arr01[m][n] = sc.nextInt();
			}
		}
		
		display(arr01);
		System.out.println("请输入第二行列式：");
		Scanner sr = new Scanner(System.in);
		for (int m = 0; m <x ; m++) {
			for (int n = 0; n < y ; n++) {

				System.out.print("第二行列式的" + (m + 1) + "行，第" + (n + 1) + "列为：");
				arr02[m][n] = sr.nextInt();
			}
		}
		System.out.println("第2行列式为：");
		display(arr02);
		for (int s = 0; s <= i; s++) {
			for (int r = 0; r <= y; r++) {
				System.out.println();
			}
		}
		arr03=multiply(arr01,arr02);
		System.out.println("两行列式相乘为：");
		display(arr03);
	}
       
	public static void display(int[][] h) {//将输入的行列式在控制台展示出来
		for (int m = 0; m < h.length; m++) {
			for (int n = 0; n < h[m].length; n++) {
				System.out.print(h[m][n]);
				System.out.print("\t");
			}
			System.out.println();
		}
	}

	public static int[][] multiply(int[][] a, int[][] b) {//计算两行列式相乘
		int[][] c = new int[a.length][b[0].length];
		for (int m = 0; m < a.length; m++) {
			for (int n = 0; n < b[0].length; n++) {
				for (int k = 0; k < a[0].length; k++) {
					c[m][n] += a[m][k] * b[k][n];
				}
				System.out.println();
			}
			//return c;
		}
		return c;
	}
}
